#include <ximera/input/messages.hpp>

namespace ximera { namespace input
{
    AxisChangeMessage::AxisChangeMessage(IDevice* sender, Byte axisIndex, Real lastValue, Real newValue, Real relValue):_sender(sender),
        _axisIndex(axisIndex), _lastValue(lastValue), _newValue(newValue), _relValue(relValue)
    {
    }

    void AxisChangeMessage::process()
    {
        try
        {
            if (_sender)
                _sender->onAxisChange()(_sender, _axisIndex, _lastValue, _newValue, _relValue);
        }
        catch(...)
        {
        }
    }

    AxisIntChangeMessage::AxisIntChangeMessage(IDevice* sender, Byte axisIndex, Int16 lastValue, Int16 newValue, Int16 relValue):_sender(sender),
        _axisIndex(axisIndex), _lastValue(lastValue), _newValue(newValue), _relValue(relValue)
    {
    }

    void AxisIntChangeMessage::process()
    {
        try
        {
            if (_sender)
                _sender->onAxisIntChange()(_sender, _axisIndex, _lastValue, _newValue, _relValue);
        }
        catch(...)
        {
        }
    }

    ButtonChangeMessage::ButtonChangeMessage(IDevice* sender, Byte buttonIndex, Byte lastValue, Byte newValue, Byte relValue):_sender(sender),
        _buttonIndex(buttonIndex), _lastValue(lastValue), _newValue(newValue), _relValue(relValue)
    {
    }

    void ButtonChangeMessage::process()
    {
        try
        {
            if (_sender)
                _sender->onButtonChange()(_sender, _buttonIndex, _lastValue, _newValue, _relValue);
        }
        catch(...)
        {
        }
    }

    ButtonDownMessage::ButtonDownMessage(IDevice* sender, Byte buttonIndex):_sender(sender),
        _buttonIndex(buttonIndex)
    {
    }

    void ButtonDownMessage::process()
    {
        try
        {
            if (_sender)
                _sender->onButtonDown()(_sender, _buttonIndex);
        }
        catch(...)
        {
        }
    }

    ButtonUpMessage::ButtonUpMessage(IDevice* sender, Byte buttonIndex):_sender(sender),
        _buttonIndex(buttonIndex)
    {
    }

    void ButtonUpMessage::process()
    {
        try
        {
            if (_sender)
                _sender->onButtonUp()(_sender, _buttonIndex);
        }
        catch(...)
        {
        }
    }
}}
